<?php

/**
 * Subclass for representing a row from the 'conf_session' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Session extends BaseSession
{

#get number of registrations associated to relevant session
  public function getNbSessionRegistrations()
  {  
    return $this->countSessionRegistrations();
  }
    //is a session full?
  public function isFull(){
	$a = $this->countSessionRegistrations();
	$b = $this->getMaxEnroll();
	if($a >= $b){
		return true;
	}
	return false;
  }

#get name of the conference
  public function getConferenceName()
  {  
    return $this->getConference()->getName();
  }
  
  public static function getNumberUniqueDays($selectedSessions)
  {
    $totalUniqueDays = 0; 
    
    if (count($selectedSessions) > 0)
    {
      foreach ($selectedSessions as $selectedSession)
      {
        $days[]=$selectedSession->getTimeStart('d');
      }
      
      $totalUniqueDays = count(array_unique($days));
    }
    return $totalUniqueDays;

  }
  
  //return the id of session that is clashed with session in $sessionIDArray
  //assuming $sessionIDArray is mutually exclusive
  public static function getClashedSessionIDs($sessionIDArray)
  {
    $clashedIDArray = array ();
  
    foreach ($sessionIDArray as $registeredSessionID)
    {
      $c = new Criteria();
      $c->add(SessionPeer::ID, $registeredSessionID);
      $registeredSession = SessionPeer::doSelectOne($c);

      $c = new Criteria();
      $c->clearSelectColumns();
      $c->addSelectColumn(SessionPeer::ID);
      $c->add(SessionPeer::CONFERENCE_ID, $registeredSession->getConferenceId());
      $c->addAnd(SessionPeer::TIME_START, $registeredSession->getTimeEnd(), Criteria::LESS_EQUAL); 
      $c->addAnd(SessionPeer::TIME_END, $registeredSession->getTimeStart(), Criteria::GREATER_EQUAL);
      
      $rsClashedSessionIDs = SessionPeer::doSelectRS($c);
              
      while($rsClashedSessionIDs->next())
      {
        if (!in_array($rsClashedSessionIDs->getInt(1), $clashedIDArray))
        {
          $clashedIDArray[] = $rsClashedSessionIDs->getInt(1);
        }
        
      }
    }
    
    return $clashedIDArray;
  }

    
  
  
}